<template>
	<view class="loginZ">
		<view class="LTitle flex-ct u-m-b-40">节鱼登录</view>
		<view class="Llogin u-m-80">
			<u-field v-model="username" label="账号" placeholder="请填写账号">
			</u-field>
			<u-field v-model="password" label="密码" placeholder="请填写密码" password>
			</u-field>
		</view>
		<view class="Lmess u-m-l-80">
			<u-checkbox-group>
				<u-checkbox v-model="checked">记住密码</u-checkbox>
			</u-checkbox-group>
		</view>
		<view class="Lbut u-m-80">
			<u-button type="primary" :ripple="true" plain @click="login()">登录</u-button>
		</view>
	</view>
</template>

<script>
	import helper from '../../common/helper.js'
	export default {
		data() {
			return {
				username: '',
				password: '',
				checked: false
			}
		},
		created() {
			this.getLogin()
		},
		methods: {
			getLogin(){
				let that = this
				let userName = uni.getStorageSync("userName")
				that.username = userName.username
				that.password = userName.password
				that.checked = userName.checked
			},
			login(){
				let that = this
				let data = {
					username: that.username,
					password: that.password
				}
				let userName = {
					username: that.username,
					password: that.password,
					checked: that.checked
				}
				if(that.checked == true){
					uni.setStorage({
						key: "userName",
						data: userName
					})
				}
				that.postRequest(helper.loginByUsername,data).then(res => {
					if(res.data.flag == "200"){
						let serve = res.data.user
						uni.setStorage({
							key: "user",
							data: serve
						})
						uni.reLaunch({
							url: '../index/index'
						})
					}
				})
				// uni.request({
				// 	url: helper.loginByUsername,
				// 	data:data,
				// 	method: "POST",
				// 	success:function(res){
				// 		console.log(res)
				// 	}
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.loginZ {
		background-image: url(../../static/image/jiaxingBack.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;

		.LTitle {
			font-size: 60rpx;
			text-shadow: 3px -1px 3px #1998AD;
			position: relative;
			top: 200rpx;
		}

		.Llogin {
			position: relative;
			top: 300rpx;
		}
		.Lmess{
			position: relative;
			top: 250rpx;
		}
		.Lbut {
			position: relative;
			top: 200rpx;
		}
	}
</style>
